package cn.com.demo.microservice.consumer.controller;

import cn.com.demo.microservice.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class DemoController {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${services.consumer.name}")
    private String provider;
    @GetMapping("/hello/{name}")
    public String hello(@PathVariable("name") String name){
        String result = this.restTemplate.getForObject("http://"+this.provider+"/provider/hello/" + name, String.class);
        return result;
    }

    @PostMapping("/user")
    public User user(@RequestBody User user){
        User user1 = this.restTemplate.postForObject("http://Provider03/provider/user",user, User.class);
        return user1;
    }
}
